using System.Collections.Generic;

namespace BanckUtil
{
    class Bank
    {
        private List<Account> accounts;

        public Bank()
        {
            accounts = new List<Account>();
        }

        public bool OpenAccount(string id, string pwd)
        {
            if (isExist(id)) return false;

            Account account = new Account(id, pwd);
            accounts.Add(account);
            return true;
        }

        public bool CloseAccount(string id, string pwd)
        {
            if (!isExist(id)) return false;
            int index = accounts.FindIndex(account => {
                return account.GetId() == id;
            });

            accounts.RemoveAt(index);

            return true;
        }

        public Account FindAccount(string id)
        {
            Account result = null;

            accounts.ForEach(account =>
            {
                if (account.GetId().Equals(id))
                {
                    result = account;
                }
            });

            return result;
        }

        private bool isExist(string id)
        {
            return accounts.Exists(account => account.GetId() == id);
        }
    }
}
